package pers.cz.log;

import pers.cz.json.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 日志打印工具
 * @program: PostGirl-panent
 * @description: LogUtils
 * @author: Cheng Zhi
 * @create: 2021-12-19 11:01
 **/
public class LogUtils {

    private static Logger log;

    static {
        log = LoggerFactory.getLogger("SYSTEM");
    }

    public LogUtils(Class clazz) {
        log = LoggerFactory.getLogger(clazz);
    }

    /**
     * 打印debug级别日志
     * @param content
     */
    public void printDebug(String content) {

        if (log.isDebugEnabled()) {
            log.debug(content);
        }
    }

    /**
     * 打印info级别日志
     * @param content
     */
    public void printInfo(String content) {
        log.info(content);
    }

    /**
     * 打印error级别日志
     * @param content
     */
    public void printError(String content) {
        log.info(content);
    }

    /**
     * 打印debug级别的复杂对象
     * @param content
     * @param object
     */
    public void printObject(String content, Object object) {

        if (log.isDebugEnabled()) {
            log.debug(content + JsonUtil.serialize(object));
        }
    }

    /**
     * 默认debug实现
     * @param msg
     */
    public static void debug(String msg) {

        if (log.isDebugEnabled()) {
            log.debug(msg);
        }
    }

    /**
     * 默认info实现
     * @param msg
     */
    public static void info(String msg)  {
        if (log.isInfoEnabled()) {
            log.info(msg);
        }
    }

    /**
     * 默认error实现
     * @param msg
     * @param e
     */
    public static void error(String msg , Exception... e) {

        log.error(msg, e);
    }

    /**
     * 默认warn实现
     * @param msg
     */
    public static void warn(String msg) {
        log.warn(msg);
    }
}
